(function($) {
    $.fn.hovertree = function(options) {
        var settings = $.extend({
            width: "",
            isCloseOther: false,
            initStatus: "keleyi"
        },
        options);
        var keleyihovertree = $(this);
        if (settings.width != "") {
            keleyihovertree.css({
                "width": settings.width
            })
        }
        keleyihovertree.find(">div").each(function() {
            if ($(this).attr("class") == null || $(this).attr("class").indexOf("hovertreeitem") < 1) {
                $(this).addClass("hovertreeitem")
            }
        });
        keleyihovertree.find(">div:not(:has(ul))").addClass("hvtcurrent");
        if (settings.initStatus == "close") {
            keleyihovertree.find(">div.hvtcurrent").has("ul").removeClass("hvtcurrent")
        } else {
            if (settings.initStatus == "expand") {
                keleyihovertree.find(">div.item").addClass("hvtcurrent")
            }
        }
        keleyihovertree.find("h3").on("click",
        function() {
            var headParent = $(this).parent();
            if (headParent.attr("class").indexOf("hvtcurrent") > 0) {
                headParent.has("ul").removeClass("hvtcurrent")
            } else {
                if (settings.isCloseOther) {
                    keleyihovertree.find(">div.hvtcurrent").has("ul").removeClass("hvtcurrent")
                }
                headParent.addClass("hvtcurrent")
            }
        });
        var liSet = $(this).find("div.hovertreeitem>ul li");
        liSet.has("ul").find("a:first").append("<b></b>");
        liSet.on("mouseenter",
        function() {
            $(this).css({
                "overflow": "visible",
                "background-color": "#eee"
            });
            var pleft = $(this).position().left,
            ptop = $(this).position().top;
            var pwidth = $(this).width(),
            ppaddingLeft = parseInt($(this).css("padding-left"));
            $(this).find(">ul").css({
                "position": "absolute",
                "left": (pleft + pwidth + ppaddingLeft).toString() + "px",
                "top": ptop.toString() + "px",
                "border": "solid 1px #ccc",
                "z-index": "2014"
            }).show()
        });
        liSet.on("mouseleave",
        function() {
            $(this).css({
                "overflow": "hidden",
                "background-color": "#fff"
            });
            $(this).find(">ul").hide()
        })
    }
} (jQuery));